// pages/teacher/qingjia/detail/detail.js
Page({
  data: {
    id: null,
    leaveInfo: null
  },

  onLoad: function(options) {
    if (options.id) {
      this.setData({
        id: options.id
      });
      this.fetchLeaveDetail(options.id);
    }
  },
  
  // 获取请假详情
  fetchLeaveDetail: function(id) {
    wx.showLoading({
      title: '加载中...',
    });
    
    // 模拟请求
    setTimeout(() => {
      // 模拟数据
      const mockLeaveDetail = {
        id: id,
        studentName: '张三',
        studentId: '2023001',
        className: '计算机科学1班',
        type: '事假',
        startTime: '2023-12-15',
        endTime: '2023-12-16',
        days: 2,
        reason: '家中有事，需要回家处理一些重要事务。希望能够批准我的请假申请，谢谢老师。',
        status: '待审批',
        applyTime: '2023-12-14 10:25',
        attachments: [
          { name: '请假证明.jpg', url: 'https://example.com/proof1.jpg' }
        ]
      };
      
      // 根据ID设置不同状态
      if (id == 2) {
        mockLeaveDetail.status = '已批准';
        mockLeaveDetail.approver = '王主任';
        mockLeaveDetail.approvalTime = '2023-12-15 14:30';
        mockLeaveDetail.comment = '情况属实，准予请假';
      } else if (id == 3) {
        mockLeaveDetail.status = '已拒绝';
        mockLeaveDetail.approver = '李主任';
        mockLeaveDetail.approvalTime = '2023-12-16 16:45';
        mockLeaveDetail.comment = '请假理由不充分，建议调整时间';
      }
      
      this.setData({
        leaveInfo: mockLeaveDetail
      });
      
      wx.hideLoading();
    }, 500);
  },
  
  // 预览附件
  previewAttachment: function(e) {
    const url = e.currentTarget.dataset.url;
    wx.previewImage({
      urls: [url],
      current: url
    });
  }
});